<!--
 * @description 章节目录
 -->
<template>
  <div class="label-category-page">
    <div class="classify-btn">
      <div class="btn-title">
        <span>章节列表</span>
      </div>
      <div class="btn-btns">
        <el-button v-if="!allListIsEdit" @click="handleAddClassify"
          >添加章节</el-button
        >
      </div>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      size="mini"
      :indent="30"
    >
      <!-- <el-table-column label="序号">
        <template slot-scope="scope">
          <template v-if="scope.row.isEdit">
            <el-input
              v-model="scope.row.sort"
              
              :maxlength="15"
              placeholder="请输入序号"
            />
          </template>
          <template v-else>
            <span :class="[scope.row.parentId != -1 && 'children']">{{
              scope.row.sort
            }}</span>
          </template>
        </template>
      </el-table-column> -->
      <el-table-column label="章节名称">
        <template slot-scope="scope">
          <template v-if="scope.row.isEdit">
            <el-input
              v-model="scope.row.chapterName"
              :class="[scope.row.parentId != -1 && 'children']"
              :maxlength="15"
              placeholder="请输入名称"
            />
          </template>
          <template v-else>
            <span :class="[scope.row.parentId != -1 && 'children']">{{
              scope.row.chapterName
            }}</span>
          </template>
        </template>
      </el-table-column>

      <el-table-column label="是否配置练习题">
        <template slot-scope="scope">
          <template v-if="scope.row.isEdit">
            <!-- <el-input
              v-model="scope.row.isConfigBank"
              class="edit-input"
              :class="[scope.row.parentId != -1 && 'children']"
              size="small"
              :maxlength="15"
              placeholder=""
            /> -->
            <el-select v-model="scope.row.isConfigBank" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </template>
          <template v-else>
            <span>
              {{ scope.row.isConfigBank == 0 ? "否" : "是" }}
            </span>
          </template>
        </template>
      </el-table-column>

      <el-table-column label="出题数量">
        <template slot-scope="scope">
          <span>{{ scope.row.questionNumber }}</span>
        </template>
      </el-table-column>
      <el-table-column label="题库名称">
        <template slot-scope="scope">
          <span>{{ scope.row.questionBankName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="移动" align="center" width="200">
        <template v-if="scope.row.id != 'MRZJ'" slot-scope="scope">
          <el-button
            :disabled="scope.row.isFirst"
            type="text"
            @click="move(scope.row, 'SY')"
            >上移</el-button
          >
          <el-button
            :disabled="scope.row.isLast"
            type="text"
            @click="move(scope.row, 'XY')"
            >下移</el-button
          >
          <el-button
            v-if="!allListIsEdit"
            class="addchild-btn"
            size="small"
            type="text"
            @click="addchild(scope.row)"
            >添加子章节</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="scope">
          <template v-if="scope.row.isEdit">
            <el-button
              type="text"
              style="font-size: 14px"
              @click="handleSave(scope.row)"
              >保存</el-button
            >
            <el-button
              type="text"
              style="font-size: 14px"
              @click="handleCancel(scope.row)"
              >取消</el-button
            >
          </template>
          <template v-else>
            <el-button
              v-if="scope.row.id != 'MRZJ'"
              type="text"
              style="font-size: 14px"
              @click="handleUpdate(scope.row)"
              >编辑</el-button
            >
          </template>
          <el-button
            v-if="scope.row.id != 'MRZJ'"
            type="text"
            style="font-size: 14px"
            @click="handleDel(scope.row)"
            >删除</el-button
          >
          <el-button
            type="text"
            style="font-size: 14px"
            @click="handleCourseware(scope.row)"
            >课件</el-button
          >
          <el-button
            v-if="!scope.row.questionBankId && scope.row.id != 'MRZJ'"
            type="text"
            style="font-size: 14px"
            @click="goPractice(scope.row)"
            >练习</el-button
          >
          <el-button
            v-if="scope.row.questionBankId && scope.row.id != 'MRZJ'"
            type="text"
            style="font-size: 14px"
            @click="goPractice(scope.row)"
            >练习</el-button
          >
          <!-- <el-button
            type="text"
            style=" font-size: 14px"
            @click="goenclosure(scope.row)"
            >附件</el-button
          > -->
          <!-- <el-button
          v-if="scope.row.questionBankId"
            type="text"
            style=" font-size: 14px"
            @click="noPractice(scope.row)"
          >删除练习</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <courseware-list
      v-if="coursewareVisible"
      :course-id="selectCourse"
      :course-classify="courseClassify"
      :chapterParentId="chapterParentId"
      @close="handleClose"
    />
    <courseware-lists
      v-if="coursewareVisibles"
      :course-id="selectCourse"
      :course-classify="courseClassify"
      :chapterParentId="chapterParentId"
      @close="handleClose"
    />
    <el-dialog
      :show-close="false"
      :visible.sync="enclosure"
      class="chapter-dialog"
      title="附件"
      center
      :fullscreen="true"
    >
      <span>
        <el-button style="padding: 8px 30px" @click="goenclosures()"
          >添加附件</el-button
        >
      </span>
      <div class="courseware-list">
        <v-table
          :list="courseList"
          tag="documentLibraryLibrarReleaseEnclosure"
          :list-loading="listLoadings"
          :filter-column="filtercolumn"
          :source-arr="sourceArr"
          @handleSelectionChange="handleSelectionChange"
        >
        </v-table>
      </div>
      <span slot="footer" class="dialog-footer" style="margin-bottom: 30px">
        <el-button style="padding: 8px 30px" @click="enclosure = false"
          >取 消</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :show-close="false"
      :visible.sync="practice"
      class="chapter-dialog"
      title="练习题"
      width="400px"
      height="600px"
      top="30vh"
      center
    >
      <el-form ref="chapterform" :model="chapterform" :rules="baserules">
        <el-form-item label="名称" prop="questionName">
          <el-input
            v-model="chapterform.questionName"
            placeholder="请输入名称"
          />
        </el-form-item>
        <el-form-item label="题库:" prop="questionBankId">
          <el-cascader
            ref="classify"
            :value="questionBankName"
            v-model="chapterform.questionBankId"
            :options="classifyOptions"
            style="width: 100%"
            clearable
            :props="classifyProps"
          />
        </el-form-item>

        <el-form-item label="出题数量" prop="questionNumber">
          <el-input
            v-model.number="chapterform.questionNumber"
            placeholder="请输入出题数量"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer" style="margin-bottom: 30px">
        <el-button style="padding: 8px 30px" @click="practice = false"
          >取 消</el-button
        >
        <el-button
          style="padding: 8px 30px"
          type="primary"
          @click="chapterOnSubmit('chapterform')"
          >确 认</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :show-close="false"
      :visible.sync="enclosures"
      class="chapter-dialog"
      title="选择附件"
      center
      :fullscreen="true"
    >
      <el-collapse-transition>
        <div class="courseware-search merge">
          <span class="svg-container">
            <svg-icon icon-class="search" />
          </span>
          <el-input
            v-model="listQuery.subjectName"
            placeholder="请输入文档名称搜索"
            class="search-input"
            @keyup.enter.native="handleFilter"
          />
          <div class="courseware-search-btn">
            <el-button class="filter-item" type="primary" @click="handleFilter"
              >搜索</el-button
            >
            <el-button class="filter-item" type="primary" @click="resettingBtn"
              >重置</el-button
            >
          </div>
        </div>
      </el-collapse-transition>
      <div class="courseware-list">
        <v-table
          :list="courseLists"
          tag="documentLibraryLibrarReleaseEnclosure"
          :list-loading="listLoadingss"
          :filter-column="filtercolumns"
          :source-arr="sourceArrs"
          @handleSelectionChange="handleSelectionChanges"
        >
        </v-table>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getLists"
      />
      <span slot="footer" class="dialog-footer" style="margin-bottom: 30px">
        <el-button style="padding: 8px 30px" @click="enclosures = false"
          >取 消</el-button
        >
        <el-button
          style="padding: 8px 30px"
          type="primary"
          @click="getenclosures"
          >确 认</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import elDragDialog from "@/directive/el-drag-dialog";
import {
  insertChapter,
  queryLessonTree,
  deleteById,
  update,
  getClassifyTree,
  courseInsert,
  courseUpdatet,
  courseDele,
  move,
  getAttachmentInfo,
  fetchList,
  addAttachment,
} from "../api/chapter";
import splitPane from "vue-splitpane";
import CoursewareList from "../components/audioList/index";
import CoursewareLists from "../components/CoursewareLists/index";
import vTable from "@/components/Table";
import Pagination from "@/components/Pagination";
export default {
  name: "audiochapter",
  directives: { elDragDialog },
  components: {
    splitPane,
    CoursewareList,
    CoursewareLists,
    vTable,
    Pagination,
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        subjectName: "",
        subjectType: "KCLX02",
      },
      pageLoading: true,
      total: 0,
      listLoading: false,
      listLoadings: false,
      listLoadingss: false,
      practice: false,
      enclosure: false,
      enclosures: false,
      courseList: [],
      courseLists: [],
      list: [],
      sourceArr: ["subjectImgUrl"],
      sourceArrs: ["subjectImgUrl"],
      options: [
        {
          value: 0,
          label: "否",
        },
        {
          value: 1,
          label: "是",
        },
      ],
      classifyOptions: [], //题库分类
      questionBankName: "",
      classifyProps: {
        label: "classifyName",
        value: "id",
        checkStrictly: true,
        // lazy: true,
        // lazyLoad(node, resolve) {
        //   getClassifyTree({ parentId: (node.data && node.data.id) || -1 }).then(res => {
        //     resolve(res.data.data)
        //   }).catch(() => {
        //     resolve([])
        //   })
        // }
      },
      coursewareVisible: false,
      //没有顺序和添加的课件列表
      coursewareVisibles: false,
      selectCourse: "", // 当前点击的课程
      courseClassify: "",
      curEditRow: {},
      allListIsEdit: false, // 章节树是否存在编辑情况，如果存在隐藏所有的添加下级按钮
      selection: [],
      classifyId: "",
      chapterParentId: "",
      questionBankRelevanceId: "",
      ctType: 0,
      id: "",
      enclosureid: "",
      multipleSelection: [],
      multipleSelections: [],
      attachment: [],
      chapterform: {
        courseId: "", //课程ID
        dataId: "", //关联ID。课程、章、节的ID
        questionBankId: [], //题库ID
        questionNumber: "", //出题数量
        questionName:'',
        type: "KHLXLX_ZJ",
      },
      baserules: {
        questionBankId: [
          { required: true, message: "请选择题库", trigger: "blur" },
        ],
        questionNumber: [
          { required: true, message: "请输入出题数量", trigger: "blur" },
        ],
        questionName: [
          { required: true, message: "请输入名称", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.courseId = this.$route.query.id;
    this.getList();
  },
  methods: {
    getenclosures() {
      const loading = this.$loading({
        lock: true,
        text: "请稍后",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      return new Promise((resolve, reject) => {
        addAttachment({ id: this.enclosureid, attachment: this.attachment })
          .then(() => {
            this.$message({
              message: "处理成功",
              type: "success",
              duration: 2000,
            });
            this.enclosure = false;
            this.enclosures = false;
            this.getList();
            loading.close();
          })
          .catch((error) => {
            this.enclosure = false;
            this.enclosures = false;
            this.getList();
            loading.close();
            reject(error);
          });
      });
    },
    getLists(obj) {
      this.listLoadingss = true;

      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        status: "KCZT01",
        subjectName: this.listQuery.subjectName,
        subjectType: "KCLX02",
      };
      return new Promise((resolve, reject) => {
        fetchList(query)
          .then((response) => {
            this.courseLists = response.data.data.rows;
            this.total = response.data.data.total;
            this.listLoadingss = false;
          })
          .catch((error) => {
            this.listLoadingss = false;
            reject(error);
          });
      });
    },
    resettingBtn() {
      this.listQuery.subjectName = "";
      for (const i in this.search) {
        this.search["" + i + ""] = "";
      }
      this.listQuery.page = 1;
      this.getLists();
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getLists();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.$emit("handleSelect", this.multipleSelection);
    },
    handleSelectionChanges(val) {
      this.multipleSelections = val;
      this.$emit("handleSelect", this.multipleSelections);
      let dataClone = this.multipleSelections.map((item) => {
        return {
          fileId: item.id,
          subjectName: item.subjectName,
          fileTypeName: item.fileTypeName,
          subjectImgUrl: item.subjectImgUrl,
          subjectClassifyIdsValue: item.subjectClassifyIdsValue,
        };
      });
      this.attachment = JSON.stringify(dataClone);
    },
    filtercolumns(scope, item) {
      return scope.row[item];
    },
    filtercolumn(scope, item) {
      return scope.row[item];
    },
    getenclosure(id) {
      this.listLoadings = true;
      return new Promise((resolve, reject) => {
        getAttachmentInfo({ id: id })
          .then((response) => {
            this.listLoadings = false;
            console.log(response, "ct");
            this.courseList = response.data.data || [];
          })
          .catch((error) => {
            this.listLoadings = false;
            reject(error);
          });
      });
    },
    //附件
    goenclosure(row) {
      this.enclosure = true;
      this.getenclosure(row.id);
      this.enclosureid = row.id;
    },
    goenclosures(row) {
      this.enclosures = true;
      this.getLists();
    },
    /**
     * 分类移动
     */
    move(row, dir) {
      const loading = this.$loading({
        lock: true,
        text: "请稍后",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      return new Promise((resolve, reject) => {
        move({ id: row.id, msg: dir })
          .then(() => {
            this.$message({
              message: "处理成功",
              type: "success",
              duration: 2000,
            });
            loading.close();
            this.getList();
          })
          .catch((error) => {
            loading.close();
            this.getList();
            reject(error);
          });
      });
    },
    goPractice(row) {
      if (row.questionBankId) {
        this.practice = true;
        this.chapterform.questionBankId = row.questionBankId;
        this.chapterform.questionNumber = row.questionNumber;
        this.chapterform.questionName = row.questionName;
        this.id = row.questionBankRelevanceId;

        this.getClassify();
        console.log(row, "2222");
        this.ctType = 1;
      } else {
        this.ctType = 0;
        this.chapterform = {};
        this.practice = true;
        this.chapterform.dataId = row.id;
       this.chapterform.questionName = row.chapterName
        this.getClassify();
      }
    },
    noPractice(row) {
      const loading = this.$loading({
        lock: true,
        text: "请稍后",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      return new Promise((resolve, reject) => {
        courseDele({ id: row.questionBankId })
          .then(() => {
            loading.close();
            this.$message({
              title: "成功",
              message: "删除成功",
              type: "success",
              duration: 2000,
            });
            this.getList();
          })
          .catch((error) => {
            loading.close();
            reject(error);
          });
      });
    },
    chapterOnSubmit() {
      this.$refs["chapterform"].validate((valid) => {
        if (valid) {
          this.chapterform.courseId = this.courseId;
          this.chapterform.type = "KHLXLX_ZJ";

          const loading = this.$loading({
            lock: true,
            text: "请稍后",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.3)",
          });
          if (this.ctType == 0) {
            this.chapterform.questionBankId =
              this.chapterform.questionBankId.length > 0
                ? this.chapterform.questionBankId[
                    this.chapterform.questionBankId.length - 1
                  ]
                : "";
            return new Promise((resolve, reject) => {
              courseInsert(this.chapterform)
                .then(() => {
                  loading.close();
                  this.$message({
                    title: "成功",
                    message: "创建成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.practice = false;
                  this.getList();
                })
                .catch((error) => {
                  reject(error);
                  loading.close();
                });
            });
          } else {
            console.log(this.chapterform.questionBankId);
            if (Array.isArray(this.chapterform.questionBankId)) {
              this.chapterform.questionBankId =
                this.chapterform.questionBankId.length > 0
                  ? this.chapterform.questionBankId[
                      this.chapterform.questionBankId.length - 1
                    ]
                  : "";
            }
            const from = {
              questionBankId: this.chapterform.questionBankId,
              questionNumber: this.chapterform.questionNumber,
              questionName: this.chapterform.questionName,
              id: this.id,
            };
            console.log(from.questionBankId, "333");
            return new Promise((resolve, reject) => {
              courseUpdatet(from)
                .then(() => {
                  loading.close();
                  this.$message({
                    title: "成功",
                    message: "修改成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.practice = false;
                  this.getList();
                })
                .catch((error) => {
                  reject(error);
                  loading.close();
                });
            });
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    /**
     * 获取题库分类
     */
    getClassify() {
      return new Promise((resolve, reject) => {
        getClassifyTree({ classifyType: "JNZQFL03" })
          .then(({ data }) => {
            this.classifyOptions = data.data || [];
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    //添加课件
    handleCourseware(item) {
      console.log(item, "3333");
      this.selectCourse = item.courseId;
      this.courseClassify = item.courseClassify;
      this.chapterParentId = item.id;
      if (item.id === "MRZJ") {
        this.coursewareVisibles = true;
      } else {
        this.coursewareVisible = true;
      }
    },
    handleClose() {
      this.coursewareVisible = false;
      //没有拖拽功能的课件列表
      this.coursewareVisibles = false;
      this.getList();
    },
    // 取消
    handleCancel(row) {
      if (row.id) {
        row["classifyName"] = this.curEditRow.classifyName;
        row["status"] = this.curEditRow.status;
        this.findPathByLeafId(row.id, this.list).isEdit = false;
      } else {
        if (row.parentId) {
          this.findPathByLeafId(row.parentId, this.list).children.shift();
        } else {
          this.list.shift();
        }
      }
      this.allListIsEdit = false;
    },
    handleUpdate(row) {
      if (this.allListIsEdit) {
        this.$message({
          message: "请先保存新添加章节",
          type: "warning",
        });
        return;
      } else {
        this.allListIsEdit = true;
        this.curEditRow = Object.assign({}, row);
        this.findPathByLeafId(row.id, this.list).isEdit = true;
      }
    },
    handleSave(row) {
      console.log(row.id, "111");
      var obj = {
        id: row.id,
        courseId: this.$route.query.id,
        chapterParentId: row.parentId || -1,
        chapterName: row.chapterName,
        isConfigBank: row.isConfigBank,
        sort: row.sort,
        relevanceType: "KCGLLX_ZJ",
      };
      this.save(obj);
    },
    save(obj) {
      console.log(obj, "323");
      if (!obj.chapterName) {
        this.$message({
          message: "请填写章节名称",
          type: "warning",
        });
        return;
      }
      console.log(obj.isConfigBank, "ct");
      if (obj.isConfigBank == undefined) {
        this.$message({
          message: "请选择是否配置练习题",
        });
        return;
      }
      const pattern = new RegExp(
        "^\\s|[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]|\\s$"
      );
      if (pattern.test(obj.chapterName)) {
        this.$message({
          message: "请勿输入特殊字符或前后空格",
          type: "warning",
        });
        return;
      }
      const loading = this.$loading({
        lock: true,
        text: "请稍后",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      if (obj.id) {
        const ct = {
          id: obj.id,
          chapterName: obj.chapterName,
          sort: obj.sort,
          isConfigBank: obj.isConfigBank,
          relevanceType: obj.relevanceType,
        };
        return new Promise((resolve, reject) => {
          update(ct)
            .then(() => {
              this.allListIsEdit = false;
              this.$message({
                message: "处理成功",
                type: "success",
                duration: 2000,
              });
              loading.close();
              this.getList();
            })
            .catch((error) => {
              loading.close();
              reject(error);
            });
        });
      } else {
        return new Promise((resolve, reject) => {
          insertChapter(obj)
            .then(() => {
              this.allListIsEdit = false;
              this.$message({
                message: "处理成功",
                type: "success",
                duration: 2000,
              });
              loading.close();

              this.getList();
            })
            .catch((error) => {
              loading.close();
              reject(error);
            });
        });
      }
    },
    handleDel(row) {
      if (row.id) {
        this.$confirm("此操作将永久删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.del(row.id);
          })
          .catch(() => {});
      } else {
        if (row.parentId) {
          this.findPathByLeafId(row.parentId, this.list).children.shift();
        } else {
          this.list.shift();
        }
        this.allListIsEdit = false;
      }
    },
    del(id) {
      const loading = this.$loading({
        lock: true,
        text: "请稍后",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      return new Promise((resolve, reject) => {
        deleteById({ id: id })
          .then(() => {
            loading.close();
            this.$message({
              title: "成功",
              message: "删除成功",
              type: "success",
              duration: 2000,
            });
            this.getList();
          })
          .catch((error) => {
            loading.close();
            reject(error);
          });
      });
    },
    getList() {
      this.allListIsEdit = false;
      this.listLoading = true;
      return new Promise((resolve, reject) => {
        queryLessonTree({ courseId: this.$route.query.id })
          .then((response) => {
            this.listLoading = false;
            this.list = this.initData(response.data.data);
            console.log(this.list);
            this.pageLoading = false;
          })
          .catch((error) => {
            this.listLoading = false;
            this.pageLoading = false;
            reject(error);
          });
      });
    },
    /**
     * 递归增加是否可以上移下移标识
     * @param data
     * @returns {*}
     */
    initData(data, level = 1) {
      data.forEach((item, index) => {
        item["isFirst"] = false;
        item["isLast"] = false;
        item["isEdit"] = false;
        if (index === 0) {
          item["isFirst"] = true;
        }
        if (index === data.length - 1) {
          item["isLast"] = true;
        }
        item["level"] = level;
        if (item.children && item.children.length > 0) {
          return this.initData(item.children, level + 1);
        }
      });
      return data;
    },
    addchild(row) {
      this.allListIsEdit = true;
      row["_expanded"] = true;
      /* let length = ''
      if (row.children) {
        length = row.children.length
      } else {

      }*/
      const obj = {
        id: "",
        classifyName: "",
        isFirst: true,
        isLast: true,
        isEdit: true,
        parentId: row.id,
      };
      this.findPathByLeafId(row.id, this.list).children.unshift(obj);
    },
    /**
     * 根据id递归查找所在的对象
     * @param data
     * @returns {*}
     */
    findPathByLeafId(leafId, nodes, path) {
      if (path === undefined) {
        path = {};
      }
      for (var i = 0; i < nodes.length; i++) {
        var tmpPath = path;
        if (leafId === nodes[i].id) {
          tmpPath = nodes[i];
          return tmpPath;
        }
        if (nodes[i].children) {
          var findResult = this.findPathByLeafId(
            leafId,
            nodes[i].children,
            tmpPath
          );
          if (findResult) {
            return findResult;
          }
        }
      }
    },
    handleAddClassify() {
      this.allListIsEdit = true;
      const list = this.list;
      var length = list.length;
      const obj = {
        id: "",
        parentId: "",
        classifyName: "",
        isEdit: true,
        isFirst: true,
        isLast: true,
        index: length,
      };
      list.unshift(obj);
      this.$set(this, "list", list);
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss">
$dark_gray: #bfced6;
@import "@/styles/mixin.scss";
.label-category-page {
  padding: 20px;
  height: 100%;
  .el-dialog__footer {
    padding: 20px 0 0 0 !important;
    margin-bottom: 30px;
  }
  .my-dialog {
    .el-dialog__body {
      height: calc(100vh - 150px);
      overflow: hidden;
    }
    .el-dialog__footer {
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
  .content {
    overflow: auto;
    height: 87vh;
    padding-bottom: 30px;
  }
  .classify-btn {
    display: flex;
    height: 46px;
    line-height: 46px;
    .btn-title {
      flex: 1;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
      padding: 0 10px;
    }
  }
  .el-table {
    background-color: transparent;
    .cell {
      display: flex;
      align-items: center;
      text-align: left;
    }
    thead {
      th {
        font-size: 14px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        color: rgba(166, 166, 166, 1);
      }
    }
    th,
    tr {
      background-color: transparent;
    }
    tbody {
      background-color: #ffffff;
      font-weight: 500;
    }
  }
  .courseware-search {
    background-color: #fff;
    padding: 0 20px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;

      &_login {
        font-size: 20px;
      }
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: "";
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .courseware-search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .courseware-search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .courseware-search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: "";
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .courseware-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }
  .courseware-search-btn {
    display: inline-block;
    float: right;

    .el-button.is-round {
      padding: 10px 30px;
      margin-right: 34px;
    }

    .courseware-search-more {
      font-size: 14px;
      font-weight: 500;
      @include font-color($mainColor);
      cursor: pointer;
    }
  }
  .select-user {
    padding: 0;
    margin: 0;
    height: calc(100vh - 185px);
    overflow: auto;
    list-style: none;

    li {
      padding: 5px 8px;
      margin: 0;
      float: left;
      list-style: none;
      font-size: 14px;
      @include font-color($mainColor);
      @include border-color(1px, solid, $mainColor);
      border-radius: 5px;
      margin-left: 8px;
      margin-bottom: 8px;
    }
  }
}
</style>
<style scoped lang="scss">
.drag-handler {
  width: 20px;
  height: 20px;
  cursor: pointer;
  vertical-align: middle;
}

.edit-input {
  padding-right: 80px;
  &.children {
    padding-left: 20px;
  }
}

.addchild-btn {
  position: absolute;
  right: 15px;
  top: 6px;
}
</style>
